<?php
  $username = $_REQUEST['username'];
  $password = $_REQUEST['password'];
  $email = $_REQUEST['email'];
  $phone = $_REQUEST['phone'];

  include('../php/conn1.php');

  // 查询用户名是否存在
  $selectUName = "select * from users where username='$username'";
  $res = $conn->query($selectUName);
  if($res->num_rows>0){
    echo '<script>alert("注册失败,用户名已存在");</script>';
    echo '<script>location.href="../../src/register.html";</script>';
    die();
  }
  // 插入数据
  $insertUser = "insert into users (username,password,email,phone) values('$username','$password','$email','$phone')";
  echo $insertUser;
  $inserted = $conn->query($insertUser);
  if($inserted){
    echo '<script>alert("注册成功");</script>';
    echo '<script>location.href="../../src/sign.html";</script>';
  }
?>